<?php
namespace Home\Controller;
use Think\Controller;
class UserController extends Controller {
    /**
    *@author 汪
    *date 6-25
    *action 用户管理中心 展示页
    */
    public function index(){
        $this->display();
    }


    /**
     *@author 忠 ；
     *date 6-25
     *action 个人求职简历维护
     **/
    public function resumelist(){
        $this->assign('title','个人求职简历维护 ');

        $model = M('resume');
        $type = M('p_category');
        $school = M('school');
        $data= $model->where(array('uid'=>$_SESSION['user_info']['u_id']))->select();
        $cd = count($data);
        for ($i=0; $i<$cd; $i++){
            $typedata[]= $type->where(array('id'=>$data[$i]['type']))->select();
            $schooldata[]= $school->where(array('id'=>$data[$i]['school']))->select();
            $data[$i]['type'] = $typedata[$i][0]['typename'];
            $data[$i]['school'] = $schooldata[$i][0]['area'];
            $data[$i]['time']=date('Y-m-d H:i',$data[$i]['time']);
        }
        $this->assign('data',$data);

        $this->display();
    }
    /**
     *@author 忠
     *date 6-25
     *action 修改简历
     **/

    public function editresume(){
        if(IS_POST){
            $model = M('resume');
            $data =array();
            $data['userinfo']=$model->create();
            $data['userinfo']['time']= time();
            $data['userinfo']['uid']= $_SESSION['user_info']['u_id'];
            if($model->save($data['userinfo'])){
                $this->success('恭喜您，修改成功！',U('index'),5);
            }else{
                $this->error('添加失败！');
            }
        }else{

            //职业读取
            $model = M('p_category');
            $category= $model->select();
            $this->assign('categorydata',$category);

            //校院读取
            $model = M('school');
            $school= $model->select();
            $this->assign('schooldata',$school);
            $this->assign('title', '修改我的简历 ');



            $model = M('resume');
            $type = M('p_category');
            $school = M('school');
            $schooldatas= $school->select();
            $typedatas= $type->select();
            $list= $model->where(array('id'=>$_GET['id']))->select();
            $cd = count($list);
            for ($i=0; $i<$cd; $i++){
            $typedata[]= $type->where(array('id'=>$list[$i]['type']))->select();
                $schooldata[]= $school->where(array('id'=>$list[$i]['school']))->select();
                $list[$i]['time']=date('Y-m-d H:i',$list[$i]['time']);
                $list[$i]['id']=$_GET['id'];
            }

            $this->assign('last',$list);
            $schoolcd = count($schooldatas);

            for ($i=0; $i<$schoolcd; $i++){
                $schooldatas[$i]['userid']=$schooldata[0][0]["id"];
            }

            $typecd = count($typedatas);
            for ($i=0; $i<$typecd; $i++){
                $typedatas[$i]['typeid']=$typedata[0][0]["id"];
            }

            $this->assign('typedatas',$typedatas);
            $this->assign('schooldatas',$schooldatas);

            $this->display();
            dump($list);


        }

    }
    /**
     *@author 忠；
     *date 6-25
     * action 上传简历
     **/

    public function upresume(){
        if(IS_POST){
            $model = M('resume');
            $data =array();
            $data['userinfo']=$model->create();
            $data['userinfo']['time']= time();
            $data['userinfo']['uid']= $_SESSION['user_info']['u_id'];
            $time = time();
            dump($data['userinfo']);
            if($model->add($data['userinfo']) > 0){
                $this->success('恭喜您，添加成功！',U('index'),5);
            }else{
                $this->error('添加失败！');
            }
            }else{
            $this->assign('title', '创建我的简历 ');


            //职业读取
            $model = M('p_category');
            $category= $model->select();
            $this->assign('categorydata',$category);

            //校院读取
            $model = M('school');
            $school= $model->select();
            $this->assign('schooldata',$school);
            $this->display();

        }

    }

    /**
     *@author 忠；
     *date 6-25
     * action 删除简历
     **/
    public function offresumelist(){
        $model = M('resume');
        if($model->where(array('id'=>$_GET['id']))->delete() > 0){
            $this->success('恭喜您，删除成功！',U('index'),5);
        }else{
            $this->error('删除失败！');
        }

    }
    /**
     *@author 胡益诚:修改密码；
     *date 6-23
     *action :修改密码
     **/
    public function passmodify(){
            if(IS_POST){
                    $id= $_SESSION['user_info']['u_id'];
                    $model = M('user');
                    $data = $model->where(array('u_id'=>$id))->find();

                    $oldpassword =I('post.oldpassword');
                    $password =I('post.password');
                    $repassword =I('post.repassword');

                    if($data['password']!==$oldpassword){

                        $this->error('密码不正确');
                    }
                    if($password==$repassword){
                        $model->where(array('u_id'=>$id))->setField('password',$password);
                        $this->success('修改成功！',U('User/index'),3);
                    }else{
                        $this->error("新密码不一致");
                    }
            }else{
                $this->display();
            }
    }

    /**
     *@author 上传更新照片；
     *end
     **/
    public function updateimage(){
        $this->assign('title','上传更新照片 ');
        $this->display();
    }
    /**
     *@author 诚；
     *date 6-25
     *action 我的职位收藏夹
     **/
    public function favoritein(){

        $this->assign('title','我的职位收藏夹 ');

        if(IS_SESSION){
            // $id =$_SESSION['info']['uid'];
            $id=2;
            $model = M('favor');
            $data = $model->where(array('uid'=>$id))->select();

            foreach($data as $key=>$val){
            $data[$key]['stday'] = date("Y-m-d", $val['stday']);
            $data[$key]['ovday'] = date("Y-m-d", $val['ovday']);
            }                 
            $this->assign('data',$data);
        }
        $this->display();
    }
    /**
     *@author 我的职位邀请；
     *end
     **/
    public function yaoqing(){
        $this->assign('title','收到的职位邀请 ');
        $this->display();
    }
    /**
     *@author 我的职位申请；
     *end
     **/
    public function shenqing(){
        $this->assign('title','我的职位申请 ');
        $this->display();
    }
    /**
     *@author 收到的社团邀请；
     *end
     **/
    public function community_yaoqing(){
        $this->assign('title','收到的社团邀请 ');
        $this->display();
    }
    /**
     *@author 社团申请记录；
     *end
     **/

    public function community_shenqing(){
        $this->assign('title','社团申请记录 ');
        $this->display();
    }
    /**
     *@author 收到的工作邀请；
     *end
     **/
    public function community_list(){
        $this->assign('title','收到的工作邀请 ');
        $this->display();
    }
    /**
     *@author 我的校园社团管理；
     *end
     **/
    public function organization_organizationlist(){
        $this->assign('title','我的校园社团管理 ');
        $this->display();
    }

    /**
     *@author 骗子举报；
     *end
     **/
    public function qzjl_qzjllist(){
        $this->assign('title','骗子举报 ');
        $this->display();
    }

}